<?php

namespace app\gameapp\controller\toupiao;

use think\Controller;
use think\Request;
use think\Session;
use think\Db;

class Edit extends Controller
{
    // 初始化数据页面
    public function index()
    {
        $uid = Session::get('uid', 'home');
        $data = [];
        $data['cTime'] = time();
        $data['uid'] = $uid;
        // 创建投票活动插入活动表数据
        $actionlist = Db::table('xt_action_list')->insert($data);
        $actionId = Db::name('action_list')->getLastInsID();
        // 初始化投票活动数据
        $base['actionId'] = $actionId;
        $base['voteBeginTime'] = date('Y-m-d H:i:s');
        $base['voteEndTime'] = date('Y-m-d H:i:s');
        $base['applyBeginTime'] = date('Y-m-d H:i:s');
        $base['applyEndTime'] = date('Y-m-d H:i:s');
        $votebaseset = Db::table('xt_g_vote_base_set')->insert($base);
        // 初始化投票活动样式
        $style['actionId'] = $actionId;
        $votestyleset = Db::table('xt_g_vote_style_set')->insert($style);

        // 初始化成功跳转
        $this->success('初始成功',url('gameapp/toupiao.edit/edit',['actionId'=>$actionId]));
    }

    // 跳转编辑页面
    public function edit($actionId)
    {
        // 查询投票对应的基础信息
        $vote = Db::table('xt_g_vote_base_set')->where(['actionId' => $actionId])->find();
        // 查询投票对应的样式信息
        $style = Db::table('xt_g_vote_style_set')->where(['actionId' => $actionId])->find();
        $this->assign([
            'vote' => $vote,
            'style' => $style
        ]);
        return $this->fetch('editindex');
    }

    // 保存预览更新
    public function update($actionId)
    {

    }



    public function preview()
    {
        return $this->fetch('view');
    }
}